<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;

/* @var $this yii\web\View */
/* @var $model app\models\Audio */
/* @var $form yii\widgets\ActiveForm */
?>
<link href="ueditor/themes/default/css/umeditor.css" type="text/css" rel="stylesheet">

<div class="audio-form">

    <?php $form = ActiveForm::begin(); ?>

    <?= $form->field($model, 'title')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'description')->textarea(['rows' => 6]) ?>

<!--    这个是保存图片，应该是保存url的，所以这里需要js上传到七牛，然后获取url在保存。设置为只读，不允许用户填写-->
    <?= $form->field($model, 'audio_pic')->textInput(['id'=>'audio_pic', 'maxlength' => true, 'readonly'=>true]) ?>

    <?= $form->field($model, 'audio_url')->textInput(['id'=>'audio_url', 'maxlength' => true, 'readonly'=>true]) ?>

    <?= $form->field($model, 'length')->input('time') ?>

    <?= $form->field($model, 'music_lyric')->textarea(['rows' => 6, 'placeholder'=>'请使用lrc格式的歌词']) ?>

    <?= $form->field($model, 'release_time')->input('datetime-local', ['value'=>date('Y-m-d\TH:i:s', strtotime($model->release_time))]) ?>

    <?= $form->field($model, 'anchor_id')->textInput() ?>

    <?= $form->field($model, 'poducer_id')->textInput() ?>

    <br>

    <script type="text/plain" name="Audio[lyric]" id="myEditor" style="width:100%;height:240px;"><?=$model->lyric?></script>

    <div class="form-group">
        <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
    </div>

    <?php ActiveForm::end(); ?>

</div>

<!-- 这两个是七牛前端的js sdk -->
<script src="js/lib/qiniu/plupload.full.min.js"></script>
<script src="js/lib/qiniu/qiniu.js"></script>
<script  src="js/lib/jquery/jquery.min.js"></script>
<script  src="ueditor/umeditor.config.js"></script>
<script  src="ueditor/umeditor.min.js"></script>
<script>
    var um = UM.getEditor('myEditor');
    var uploader = Qiniu.uploader({
        runtimes: 'html5,flash,html4',
        browse_button: 'audio_pic',
         uptoken_url: '/sundry/upload-token',
        get_new_uptoken: false,
        unique_names: true,
        domain: 'http://7xss8o.com1.z0.glb.clouddn.com/',
        max_file_size: '100mb',
        flash_swf_url: 'path/of/plupload/Moxie.swf',
        max_retries: 3,
        dragdrop: true,
        drop_element: 'container',
        chunk_size: '4mb',
        auto_start: true,
        init: {
            'FileUploaded': function(up, file, info) {
                var domain = up.getOption('domain');
                var res = JSON.parse(info);
                var sourceLink = domain + res.key;
                // 这句话就是选择id是audio_pic的，把它的值改为sourceLink
                $("#audio_pic").val(sourceLink);
            }
        }
    });
    var uploader2 = Qiniu.uploader({
        runtimes: 'html5,flash,html4',
        browse_button: 'audio_url',
        uptoken_url: '/sundry/upload-token',
        get_new_uptoken: false,
        unique_names: true,
        domain: 'http://7xss8o.com1.z0.glb.clouddn.com/',
        max_file_size: '100mb',
        flash_swf_url: 'path/of/plupload/Moxie.swf',
        max_retries: 3,
        dragdrop: true,
        drop_element: 'container',
        chunk_size: '4mb',
        auto_start: true,
        init: {
            'FileUploaded': function(up, file, info) {
                var domain = up.getOption('domain');
                var res = JSON.parse(info);
                var sourceLink = domain + res.key;
                // 这句话就是选择id是audio_pic的，把它的值改为sourceLink
                $("#audio_url").val(sourceLink);
            }
        }
    });
</script>
